<?php
//旧版本需要引入这个，新版本则不需要再次引入了
//import('TagLib');
/**
 * 自定义标签库
 */
Class TagLibHd extends TagLib {
    Protected $tags = array(
        //标签属性例如<input name='' value=''/>
        //<div width=''></div>
        //其中width name value都代表属性
        //close=0为非闭合标签(例如input标签) close=1为闭合标签(例如div为闭合标签)，默认为1闭合标签
        'nav' => array('attr' => 'limit,order','close'=>1),
        //方法而自定义标签
        'hot' => array('attr' => 'limit','close' => 1),
    );

    //如何使用标签
    /**
     * @param $attr  代表传入进来的属性
     * @param $content  代表闭合标签里面的内容  例如 <nav limit='' order=''><span></span><a href=''></a></nav> $content代表<span></span><a href=''></a>
     */
    Public function _nav($attr,$content){
        $attr = $this -> parseXmlAttr($attr);
//        p($attr);
//        p($content);
        $str = <<<str
<?php
    \$_nav_cate = M('cate')->order("{$attr['order']}")->select();
    import('Class.Category',APP_PATH);
    \$_nav_cate = Category::unlimitedForLayer(\$_nav_cate);
    foreach(\$_nav_cate as \$_nav_cate_v):
        extract(\$_nav_cate_v);
        \$url = U('/c_'.\$id);
?>
str;
        $str .= $content;
        $str .= '<?php endforeach;?>';
    return $str;
    }

    Public function _hot($attr,$content){
        $attr = $this -> parseXmlAttr($attr);
        $limit = $attr['limit'];
        $str = '<?php ';
        $str .='$field = array("id","title","click");';
        $str .= '$_hot_blog = M("blog") -> field($field) -> limit('.$limit.') -> order("click DESC") -> select();';
        $str .= 'foreach ($_hot_blog as $_hot_value):';
        $str .= 'extract($_hot_value);';
        $str .= '$url = U("/".$id);?>';
        $str .= $content;
        $str .= '<?php endforeach;?>';
        return $str;
    }
}